package com.zzz.restcomponent.controller;

import com.zzz.restcomponent.vo.UserVo;
import com.zzz.treecomponent.util.PrefixTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/public")
public class PublicController {
    @Autowired
    RedisTemplate<String, Object> redisTemplate;


    @Autowired
    PrefixTree prefixTree;

    @PostMapping("/test")
    public void test() {
        redisTemplate.opsForValue().set("user:name:1", UserVo.builder().age(100).name("张三").config("{select}").build());
        System.out.println("a");
    }

    @PostMapping("get")
    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @GetMapping("/zanghua")
    public Object filter(String zanghua) {
        StringBuilder stringBuilder = new StringBuilder(zanghua);
        prefixTree.filter(stringBuilder);
        return stringBuilder;
    }
}
